{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Best Poker Hand"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: bestHand"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #最好的扑克手牌"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组&nbsp;<code>ranks</code>&nbsp;和一个字符数组&nbsp;<code>suit</code>&nbsp;。你有&nbsp;<code>5</code>&nbsp;张扑克牌，第&nbsp;<code>i</code>&nbsp;张牌大小为&nbsp;<code>ranks[i]</code>&nbsp;，花色为&nbsp;<code>suits[i]</code>&nbsp;。</p>\n",
    "\n",
    "<p>下述是从好到坏你可能持有的 <strong>手牌类型&nbsp;</strong>：</p>\n",
    "\n",
    "<ol>\n",
    "\t<li><code>\"Flush\"</code>：同花，五张相同花色的扑克牌。</li>\n",
    "\t<li><code>\"Three of a Kind\"</code>：三条，有 3 张大小相同的扑克牌。</li>\n",
    "\t<li><code>\"Pair\"</code>：对子，两张大小一样的扑克牌。</li>\n",
    "\t<li><code>\"High Card\"</code>：高牌，五张大小互不相同的扑克牌。</li>\n",
    "</ol>\n",
    "\n",
    "<p>请你返回一个字符串，表示给定的 5 张牌中，你能组成的 <strong>最好手牌类型</strong>&nbsp;。</p>\n",
    "\n",
    "<p><strong>注意：</strong>返回的字符串&nbsp;<strong>大小写</strong>&nbsp;需与题目描述相同。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"]\n",
    "<b>输出：</b>\"Flush\"\n",
    "<b>解释：</b>5 张扑克牌的花色相同，所以返回 \"Flush\" 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"]\n",
    "<b>输出：</b>\"Three of a Kind\"\n",
    "<b>解释：</b>第一、二和四张牌组成三张相同大小的扑克牌，所以得到 \"Three of a Kind\" 。\n",
    "注意我们也可以得到 \"Pair\" ，但是 \"Three of a Kind\" 是更好的手牌类型。\n",
    "有其他的 3 张牌也可以组成 \"Three of a Kind\" 手牌类型。</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"]\n",
    "<b>输出：</b>\"Pair\"\n",
    "<b>解释：</b>第一和第二张牌大小相同，所以得到 \"Pair\" 。\n",
    "我们无法得到 \"Flush\" 或者 \"Three of a Kind\" 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>ranks.length == suits.length == 5</code></li>\n",
    "\t<li><code>1 &lt;= ranks[i] &lt;= 13</code></li>\n",
    "\t<li><code>'a' &lt;= suits[i] &lt;= 'd'</code></li>\n",
    "\t<li>任意两张扑克牌不会同时有相同的大小和花色。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [best-poker-hand](https://leetcode.cn/problems/best-poker-hand/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [best-poker-hand](https://leetcode.cn/problems/best-poker-hand/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[13,2,3,1,9]\\n[\"a\",\"a\",\"a\",\"a\",\"a\"]', '[4,4,2,4,4]\\n[\"d\",\"a\",\"a\",\"b\",\"c\"]', '[10,10,2,12,9]\\n[\"a\",\"b\",\"c\",\"a\",\"d\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return \"Flush\"\n",
    "        else:\n",
    "            ranks=collections.Counter(ranks)\n",
    "            if any(i>=3 for i in ranks.values()):\n",
    "                return \"Three of a Kind\"\n",
    "            elif any(i==2 for i in ranks.values()):\n",
    "                return \"Pair\"\n",
    "            else:\n",
    "                return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:return \"Flush\"\n",
    "        dicr = {}\n",
    "        for i in range(len(ranks)):\n",
    "            if ranks[i] not in dicr:\n",
    "                dicr[ranks[i]] = 1\n",
    "            else:\n",
    "                dicr[ranks[i]] += 1\n",
    "        if len(dicr)==5:return \"High Card\"\n",
    "        for [a,b] in dicr.items():\n",
    "            if b>2:return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        flower=suits[0]\n",
    "        flag=0\n",
    "        for i in range(1,5):\n",
    "            if flower!=suits[i]:\n",
    "                flag=1\n",
    "                break\n",
    "        if flag==0:\n",
    "            return 'Flush'\n",
    "        else:\n",
    "            dic={}\n",
    "            for x in ranks:\n",
    "                if x not in dic:\n",
    "                    dic[x]=1\n",
    "                else:\n",
    "                    dic[x]+=1\n",
    "            Max=0\n",
    "            for x in dic:\n",
    "                Max=max(Max,dic[x])\n",
    "            if Max>=3:\n",
    "                return 'Three of a Kind'\n",
    "            elif Max==2:\n",
    "                return 'Pair'\n",
    "            else:\n",
    "                return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if all(item==suits[0] for item in suits):\n",
    "            return \"Flush\"\n",
    "        m = {}\n",
    "        for i in range(5):\n",
    "            if ranks[i] not in m.keys():\n",
    "                m[ranks[i]] = 1\n",
    "            else:\n",
    "                m[ranks[i]] += 1\n",
    "        sm = sorted(m.items(), key=lambda row: row[1], reverse=True)\n",
    "        # print(sm)\n",
    "        if sm[0][1] >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        for row in sm:\n",
    "            if row[1] == 2:\n",
    "                return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        counter = Counter(ranks)\n",
    "        for count in sorted(counter.values(),reverse = True):\n",
    "            if count >= 3:\n",
    "                return \"Three of a Kind\"\n",
    "            if count == 2:\n",
    "                return \"Pair\"\n",
    "        if len(set(ranks)) == 5:\n",
    "            return \"High Card\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "      # ranks.sort()\n",
    "      if len(set(suits)) == 1:\n",
    "        return \"Flush\"\n",
    "      # elif collections.Counter(ranks)[ranks[2]]>=3:\n",
    "      #   return \"Three of a Kind\"\n",
    "      # elif len(set(ranks))<=4:\n",
    "      #   return \"Pair\"\n",
    "      # elif len(set(ranks)) == 5:\n",
    "      #   return \"High Card\"\n",
    "      if len(set(ranks)) == 5:\n",
    "        return \"High Card\"\n",
    "      tmp = collections.Counter(ranks)\n",
    "      for k,v in tmp.items():\n",
    "        if v >2:\n",
    "          return \"Three of a Kind\"\n",
    "      return \"Pair\"\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        k = list(Counter(ranks).items())\n",
    "        k.sort(key= lambda x: x[1], reverse=True)\n",
    "        for x, y in k:\n",
    "            if y >= 3:\n",
    "                return 'Three of a Kind'\n",
    "            if y == 2:\n",
    "                return 'Pair'\n",
    "        if len(k) == 5:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        dict_ranks = {}\n",
    "        dict_suit = {}\n",
    "        same = 0\n",
    "        for i in suits:\n",
    "            print(i)\n",
    "            if i != suits[0]:\n",
    "                print(i)\n",
    "                break\n",
    "            same = same + 1 \n",
    "            if same == 5:\n",
    "                return 'Flush'\n",
    "        same = 0\n",
    "        for i in ranks:\n",
    "            dict_ranks[i] = 0\n",
    "        for i in ranks:\n",
    "            dict_ranks[i] = dict_ranks[i] + 1\n",
    "        for i in ranks:\n",
    "            if dict_ranks[i]>same:\n",
    "                same = dict_ranks[i]\n",
    "        if same == 2:\n",
    "            return 'Pair'\n",
    "        elif same >= 3:\n",
    "            return 'Three of a Kind'\n",
    "        else:\n",
    "            return 'High Card'    \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        d = collections.defaultdict(set)\n",
    "        for i in range(5):\n",
    "            d[ranks[i]].add(suits[i])\n",
    "        \n",
    "        \n",
    "        cnt = 0\n",
    "        for j in d.values():\n",
    "            cnt = max(cnt, len(j))\n",
    "            \n",
    "        return 'Pair' if cnt == 2 else 'Three of a Kind'\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [rank, cnt] in h.items():\n",
    "            if cnt > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        num2cnt = {}\n",
    "        max_cnt = 0\n",
    "        for num in ranks:\n",
    "            num2cnt[num] = num2cnt.get(num, 0) + 1\n",
    "            if num2cnt[num] > max_cnt:\n",
    "                max_cnt = num2cnt[num]\n",
    "        if max_cnt >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        if max_cnt == 2:\n",
    "            return \"Pair\"\n",
    "        return \"High Card\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        # 先判断好牌\n",
    "        cur=\"High Card\"\n",
    "        # 同花\n",
    "        if len(set(suits))==1:\n",
    "            cur=\"Flush\"\n",
    "            return cur\n",
    "        # 对子，3 条，可以看数字的出现次数\n",
    "        dic=Counter(ranks)\n",
    "        for k,v in dic.items():\n",
    "            if v>=3:\n",
    "                cur=\"Three of a Kind\"\n",
    "            elif v==2:\n",
    "                if cur !=\"Three of a Kind\":\n",
    "                    cur=\"Pair\"\n",
    "        return cur"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return \"Flush\"\n",
    "        elif len(set(ranks))==5:\n",
    "            return \"High Card\"\n",
    "        else:\n",
    "            count=[0]*len(ranks)\n",
    "            for i in ranks:\n",
    "                count[ranks.index(i)]+=1\n",
    "            if max(count)>=3:\n",
    "                return \"Three of a Kind\"\n",
    "            else:\n",
    "                return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        c = Counter(ranks)\n",
    "        max1 = max(c.values())\n",
    "\n",
    "        return 'Pair' if max1 == 2 else 'Three of a Kind'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        suits = set(suits)\n",
    "        if len(suits) == 1:\n",
    "            return \"Flush\"\n",
    "        hashmap = collections.defaultdict(int)\n",
    "        for rank in ranks:\n",
    "            hashmap[rank] += 1\n",
    "        arr = hashmap.values()\n",
    "        if max(arr) == 1:\n",
    "            return \"High Card\"\n",
    "        elif max(arr) == 2:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"Three of a Kind\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        cnt = Counter(ranks)\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        elif any([v > 2 for v in cnt.values()]):\n",
    "            return \"Three of a Kind\"\n",
    "\n",
    "        elif any([v == 2 for v in cnt.values()]):\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        dic = Counter(ranks)\n",
    "        v = max(dic.values())\n",
    "        if v >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif 2 <= v < 3:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if suits.count(suits[0]) == 5:\n",
    "            return \"Flush\"\n",
    "        else:\n",
    "            cou = 0\n",
    "            for i in range(0,5):\n",
    "                if ranks.count(ranks[i]) > cou:\n",
    "                    cou = ranks.count(ranks[i])\n",
    "            if cou >= 3 :\n",
    "                return \"Three of a Kind\"\n",
    "            elif cou == 2:\n",
    "                return \"Pair\"\n",
    "            else:\n",
    "                return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        d = collections.defaultdict(set)\n",
    "        for i in range(len(ranks)):\n",
    "            d[ranks[i]].add(suits[i])\n",
    "        \n",
    "        \n",
    "        cnt = 0\n",
    "        for j in d.values():\n",
    "            cnt = max(cnt, len(j))\n",
    "            \n",
    "        return 'Pair' if cnt == 2 else 'Three of a Kind'\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len( set(suits)) ==1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for a, b in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(list(set(suits))) == 1:\n",
    "            return \"Flush\"\n",
    "        elif len([i for i in ranks if ranks.count(i) >=3]):\n",
    "            return \"Three of a Kind\"\n",
    "        elif len([i for i in ranks if ranks.count(i) >=2]):\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\"\n",
    "     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return 'Flush'\n",
    "        counter=[0]*13\n",
    "        for i in range(len(ranks)):\n",
    "            counter[ranks[i]-1]+=1\n",
    "        if max(counter)>=3:\n",
    "            return 'Three of a Kind'\n",
    "        elif max(counter)==2:\n",
    "            return 'Pair'\n",
    "        else:\n",
    "            return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        h={}\n",
    "        s1=set()\n",
    "        for x in suits:\n",
    "            s1.add(x)\n",
    "        if len(s1)==1:\n",
    "            return 'Flush'\n",
    "        for x in ranks:\n",
    "            h[x]=h.get(x,0)+1\n",
    "        ans=0\n",
    "        for x in h:\n",
    "            ans=max(ans,h[x])\n",
    "        if ans>=3:\n",
    "            return 'Three of a Kind'\n",
    "        elif ans==2:\n",
    "            return 'Pair'\n",
    "        else:\n",
    "            return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        # 检查是否是同花\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        # 统计出现的次数\n",
    "        Coun = Counter(ranks)\n",
    "        # 检查是否为高张（如果set的len为5那一定为高张）\n",
    "        if len(Coun) == 5:\n",
    "            return \"High Card\"\n",
    "        # 检查是否是三条\n",
    "        for [a,b] in Coun.items():\n",
    "            if b >= 3:\n",
    "                return \"Three of a Kind\"   \n",
    "        # 默认为对子\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return \"Flush\"\n",
    "        for i in ranks:\n",
    "            if ranks.count(i)>=3:\n",
    "                return \"Three of a Kind\"\n",
    "        for i in ranks:\n",
    "            if ranks.count(i)==2:\n",
    "                return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def count_repeat(self, LL):\n",
    "        # 统计列表LL中各元素的重复次数,并按照降序进行排列\n",
    "        repeat_num = {}\n",
    "        for i in LL:\n",
    "            if i in repeat_num:\n",
    "                repeat_num[i] += 1\n",
    "            else:\n",
    "                repeat_num[i] = 1\n",
    "        # 降序排列\n",
    "        LL_sorted = sorted(repeat_num.items(), key=lambda x:x[1], reverse=True)\n",
    "        \n",
    "        return LL_sorted\n",
    "\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        card_type = {5: \"Flush\", 3: \"Three of a Kind\", 2: \"Pair\", 1: \"High Card\"}\n",
    "        # 只需要统计2个list中重复最多的元素,然后就可以根据其出现的“次数”来索引card_type中对应的“手牌类型”\n",
    "        s_res = self.count_repeat(suits)\n",
    "        r_res = self.count_repeat(ranks)\n",
    "\n",
    "        index = r_res[0][0]\n",
    "        num = r_res[0][1]\n",
    "        \n",
    "        if s_res[0][1] == 5: # 表示如果suit中重复次数最多的字符数量为5\n",
    "            return card_type[5]\n",
    "        elif num >=3:\n",
    "            return card_type[3]\n",
    "        elif num == 2:\n",
    "            return card_type[2]\n",
    "        else:\n",
    "            return card_type[1]\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return 'Flush'\n",
    "        cnt=Counter(ranks)\n",
    "        if max(cnt.values())>=3:\n",
    "            return 'Three of a Kind'\n",
    "        elif max(cnt.values())==2:\n",
    "            return 'Pair'\n",
    "        else:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        cnt = Counter(suits)\n",
    "        if cnt[suits[0]] == 5: return \"Flush\"\n",
    "        cnt2 = Counter(ranks)\n",
    "        tp = False\n",
    "        for x, y in cnt2.items():\n",
    "            if y >= 3: return \"Three of a Kind\"\n",
    "            elif y == 2: tp = True\n",
    "        if tp: return \"Pair\"\n",
    "        if len(cnt2) == 5: return \"High Card\"\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        st=set()\n",
    "        for suit in suits:\n",
    "            st.add(suit)\n",
    "        if(len(st)==1): return 'Flush'\n",
    "        st1=Counter(ranks)\n",
    "        if(len(st1)==5): return 'High Card'\n",
    "        for [_,b] in st1.items():\n",
    "            if(b>=3): return 'Three of a Kind'\n",
    "        return 'Pair'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(list(set(suits))) == 1:\n",
    "            return \"Flush\"\n",
    "        count = list(Counter(ranks).values())\n",
    "        if max(count) >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif max(count) == 2:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        difSuits = set(suits)\n",
    "        rankCount = sorted(collections.Counter(ranks).items(), key=lambda x:x[1], reverse=True)\n",
    "\n",
    "        if len(difSuits) == 1:\n",
    "            return \"Flush\"\n",
    "        for rank, cnt in rankCount:\n",
    "            if cnt >= 3:\n",
    "                return \"Three of a Kind\"\n",
    "            elif cnt == 2:\n",
    "                return \"Pair\"\n",
    "            else:\n",
    "                return \"High Card\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        rc, sc = Counter(ranks), Counter(suits)\n",
    "        if 5 == sc.most_common(1)[0][1]:\n",
    "            return 'Flush'\n",
    "\n",
    "        r = rc.most_common(1)[0][1]\n",
    "        if r >= 3:\n",
    "            return 'Three of a Kind'\n",
    "        \n",
    "        if r >= 2:\n",
    "            return 'Pair'\n",
    "\n",
    "        return 'High Card'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        i = max(Counter(ranks).values())\n",
    "        if i == 1:\n",
    "            return \"High Card\"\n",
    "        if i == 2:\n",
    "            return \"Pair\"\n",
    "        return \"Three of a Kind\"\n",
    "        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if suits.count(suits[0]) == 5:\n",
    "            return \"Flush\"\n",
    "        maxTime = 1\n",
    "        for i in range(5):\n",
    "            maxTime = max(ranks.count(ranks[i]), maxTime)\n",
    "        if maxTime >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif maxTime == 2:\n",
    "            return \"Pair\"\n",
    "        if len(set(ranks)) == 5:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        \n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        ranks = Counter(ranks)\n",
    "\n",
    "        if max(ranks.values()) >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif max(ranks.values()) == 2:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return \"Flush\"\n",
    "        for i in set(ranks):\n",
    "            if ranks.count(i)>=3:\n",
    "                return \"Three of a Kind\"\n",
    "        for i in set(ranks):\n",
    "            if ranks.count(i)==2:\n",
    "                return \"Pair\"\n",
    "        if len(ranks)==len(set(ranks)):                \n",
    "            return \"High Card\"\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        i = max(Counter(ranks).values())\n",
    "        if i > 2:\n",
    "            return \"Three of a Kind\"\n",
    "        if i == 2:\n",
    "            return \"Pair\"\n",
    "        return \"High Card\"\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        c_rank, c_suits = collections.Counter(ranks), collections.Counter(suits)\n",
    "        if len(c_suits.keys()) == 1:\n",
    "            return \"Flush\"\n",
    "        max_cnt = 0\n",
    "        for k, v in c_rank.items():\n",
    "            max_cnt = max(max_cnt, v)\n",
    "        if max_cnt >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif max_cnt == 2:\n",
    "            return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "      ranks.sort()\n",
    "      if len(set(suits)) == 1:\n",
    "        return \"Flush\"\n",
    "      elif collections.Counter(ranks)[ranks[2]]>=3:\n",
    "        return \"Three of a Kind\"\n",
    "      elif len(set(ranks))<=4:\n",
    "        return \"Pair\"\n",
    "      elif len(set(ranks)) == 5:\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        d = collections.defaultdict(set)\n",
    "        for i in range(5):\n",
    "            d[ranks[i]].add(suits[i])\n",
    "        \n",
    "        \n",
    "        cnt = 0\n",
    "        for j in d.values():\n",
    "            cnt = max(cnt, len(j))\n",
    "            \n",
    "        return 'Pair' if cnt == 2 else 'Three of a Kind'\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        res = \"High Card\"\n",
    "        ranks.sort()\n",
    "        number = ranks[0]\n",
    "        max_n = 0\n",
    "        n = 0\n",
    "        for i in ranks:\n",
    "            if number != i:\n",
    "                n = 1\n",
    "                number = i\n",
    "            else:\n",
    "                n += 1\n",
    "            max_n = max(max_n, n)\n",
    "        print(max_n)\n",
    "        c = Counter(suits)\n",
    "        if len(c) > 1:\n",
    "            if max_n == 2:\n",
    "                res = \"Pair\"\n",
    "            elif max_n >= 3:\n",
    "                res = \"Three of a Kind\"\n",
    "        else:\n",
    "            res = \"Flush\"\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        z=1\n",
    "        for a in range(4):\n",
    "            if suits[a]!=suits[a+1]:\n",
    "                z=0\n",
    "        if z==1:\n",
    "            return \"Flush\"\n",
    "        e=0\n",
    "        for b in ranks:\n",
    "            d=0\n",
    "            for c in ranks:\n",
    "                if b==c:\n",
    "                    d+=1\n",
    "            e=max(e,d)\n",
    "        if e>=3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif e==2:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\"\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        c = Counter(ranks)\n",
    "        max1 = max(c.values())\n",
    "\n",
    "        return 'Pair' if max1 == 2 else 'Three of a Kind'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        ranks.sort()\n",
    "        suits.sort()\n",
    "        if suits[0]==suits[-1]:\n",
    "            return \"Flush\"\n",
    "        elif ranks[0]==ranks[2] or ranks[1]==ranks[3] or ranks[2]==ranks[4]:\n",
    "            return \"Three of a Kind\"\n",
    "        for i in range(4):\n",
    "            if ranks[i]==ranks[i+1]:\n",
    "                return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        \n",
    "        if len(set(ranks)) == 5:\n",
    "            return 'High Card'\n",
    "            \n",
    "        d = collections.defaultdict(set)\n",
    "        for i in range(len(ranks)):\n",
    "            d[ranks[i]].add(suits[i])\n",
    "        \n",
    "        \n",
    "        cnt = 0\n",
    "        for j in d.values():\n",
    "            cnt = max(cnt, len(j))\n",
    "            \n",
    "        return 'Pair' if cnt == 2 else 'Three of a Kind'\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(list(set(suits))) == 1:\n",
    "            return \"Flush\"\n",
    "        count = list(Counter(ranks).values())\n",
    "        if max(count) >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif max(count) == 2:\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        f=True\n",
    "        for i in suits:\n",
    "            if i != suits[0]:\n",
    "                f=False\n",
    "                break\n",
    "        if f==True:\n",
    "            return \"Flush\"\n",
    "        f=True\n",
    "        cnt=Counter(ranks)\n",
    "        for i in cnt:\n",
    "            if cnt[i]>=3:\n",
    "                return \"Three of a Kind\"\n",
    "        for i in cnt:\n",
    "            if cnt[i]==2:\n",
    "                return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        n=len(ranks)\n",
    "        if len(set(suits))==1:\n",
    "            return \"Flush\"\n",
    "        else:\n",
    "            ranks.sort()\n",
    "            t=ranks[0]\n",
    "            sum=1\n",
    "            ans=0\n",
    "            for j in range(1,n):\n",
    "                if ranks[j]==t:\n",
    "                    sum+=1\n",
    "                    ans=max(ans,sum)\n",
    "                else:\n",
    "                    sum=1\n",
    "                t=ranks[j]\n",
    "            if ans>=3:\n",
    "                return \"Three of a Kind\"\n",
    "            if ans==2:\n",
    "                return \"Pair\"\n",
    "            else:\n",
    "                return \"High Card\"\n",
    "\n",
    "\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlush(self, suits: List[str]) -> bool:\n",
    "        return suits[0] == suits[1] == suits[2] == suits[3] == suits[4]\n",
    "\n",
    "    def isThreeKind(self, ranks: List[int]):\n",
    "        ranks.sort()\n",
    "        if ranks[0] == ranks[1] == ranks[2] or ranks[1] == ranks[2] == ranks[3] or ranks[2] == ranks[3] == ranks[4]:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "    def isPair(self, ranks: List[int]) -> bool:\n",
    "        ranks.sort()\n",
    "        if ranks[0] == ranks[1] or ranks[1] == ranks[2] or ranks[2] == ranks[3] or ranks[3] == ranks[4]:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if self.isFlush(suits):\n",
    "            return \"Flush\"\n",
    "        elif self.isThreeKind(ranks):\n",
    "            return \"Three of a Kind\"\n",
    "        elif self.isPair(ranks):\n",
    "            return \"Pair\"\n",
    "        else:\n",
    "            return \"High Card\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits))==1:\n",
    "            return 'Flush'\n",
    "        if len(set(ranks))<=3:\n",
    "            if len(set(ranks))==3:\n",
    "                for i in set(ranks):\n",
    "                    if ranks.count(i)==3:\n",
    "                        return 'Three of a Kind'\n",
    "                return 'Pair'\n",
    "            return 'Three of a Kind'\n",
    "        if len(set(ranks))==4:\n",
    "            return 'Pair'\n",
    "        if len(set(ranks))==5:\n",
    "            return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return 'Flush'\n",
    "        if len(set(ranks)) == 5:\n",
    "            return \"High Card\"\n",
    "        hash1 = {j:i    for i , j in Counter(ranks).items() }\n",
    "            \n",
    "        if 3 in hash1 or 4 in hash1:\n",
    "            return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        dict1=Counter(suits)\n",
    "        aa=[i for i,j in dict1.items() if j>=5]\n",
    "        if aa!=[]:\n",
    "            return 'Flush'\n",
    "        dict2=Counter(ranks)\n",
    "        bb=[j for i,j in dict2.items() if j>=2]\n",
    "        cc=[j for i,j in dict2.items()]\n",
    "        if bb!=[] and max(bb)>=3:\n",
    "            return 'Three of a Kind'\n",
    "        elif bb!=[] and max(bb)==2:\n",
    "            return 'Pair'\n",
    "        if len(cc)>=5:\n",
    "            return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        a=ranks.count(ranks[0])\n",
    "        if suits.count(suits[0]) == 5:\n",
    "            return \"Flush\"\n",
    "        for i in range(5):\n",
    "            if a<ranks.count(ranks[i]):\n",
    "                a=ranks.count(ranks[i])\n",
    "        if a>=3:\n",
    "            return \"Three of a Kind\"\n",
    "        elif a==2:\n",
    "            return \"Pair\"\n",
    "        elif a==1:\n",
    "            return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        suitsset=set(suits)\n",
    "        ranksset=set(ranks)\n",
    "        n=len(suitsset)\n",
    "        num=len(ranksset)\n",
    "        if n==1:\n",
    "            return 'Flush'\n",
    "        if num<=2:\n",
    "            return 'Three of a Kind'\n",
    "        elif num==4:\n",
    "            return 'Pair'\n",
    "        elif num==5:\n",
    "             return 'High Card'\n",
    "        h = Counter(ranks)\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\"\n",
    "\n",
    "       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if all(suits[i - 1] == suits[i] for i in range(1, 5)):\n",
    "            return \"Flush\"\n",
    "        mx = 1\n",
    "        for i in range(5):\n",
    "            x = len([0 for j in range(5) if ranks[i] == ranks[j]])\n",
    "            mx = max(mx, x)\n",
    "        if mx > 2:\n",
    "            return \"Three of a Kind\"\n",
    "        elif mx == 2:\n",
    "            return \"Pair\"\n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        record_rank = collections.defaultdict(int)\n",
    "        record_suit = collections.defaultdict(int)\n",
    "        for i in range(5):\n",
    "            record_rank[ranks[i]] += 1\n",
    "            record_suit[suits[i]] += 1\n",
    "        if len(record_suit) == 1:\n",
    "            return 'Flush'\n",
    "        elif max(record_rank.values()) >= 3:\n",
    "            return 'Three of a Kind'\n",
    "        elif max(record_rank.values()) == 2:\n",
    "            return 'Pair'\n",
    "        elif len(record_rank) == 5:\n",
    "            return 'High Card'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        ranks1 = Counter(ranks)\n",
    "        if suits.count(suits[0]) == len(suits):\n",
    "            return \"Flush\"\n",
    "        if max(ranks1.values()) >= 3:\n",
    "            return \"Three of a Kind\"\n",
    "        if max(ranks1.values()) == 2:\n",
    "            return \"Pair\"\n",
    "  \n",
    "        return \"High Card\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bestHand(self, ranks: List[int], suits: List[str]) -> str:\n",
    "        if len(set(suits)) == 1:\n",
    "            return \"Flush\"\n",
    "        h = Counter(ranks)\n",
    "        if len(h) == 5:\n",
    "            return \"High Card\"\n",
    "        for [a, b] in h.items():\n",
    "            if b > 2:\n",
    "                return \"Three of a Kind\"\n",
    "        return \"Pair\""
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
